#!/usr/bin/python2.6
from ctypes import *
libeio = cdll.LoadLibrary('/usr/local/lib/libeio.so')

eio_cb = c_void_p

class eio_pwd(Structure):
    pass
eio_pwd._fields_ = [
    ('fd', c_int),
    ('len', c_int),
    # todo
]

class eio_req(Structure):
    pass
eio_req._fields_ = [
    ('next', POINTER(eio_req)),
    ('wd', c_int)    # todo
]

eio_init = libeio.eio_init
eio_init.restype  = c_int
eio_init.argtypes = [c_void_p, c_void_p]

eio_poll = libeio.eio_poll
eio_poll.argtypes = []
eio_poll.restype  = c_int

eio_mkdir = libeio.eio_mkdir
eio_mkdir.argtypes = [c_char_p, c_uint, c_int, c_int, c_void_p]
eio_mkdir.restype  = POINTER(eio_req)

# <!-- test demo -->
import os

def getvalue(num):
    return 100 + num

def main():
    libdemo = cdll.LoadLibrary('./demo.so')
    func_arg = libdemo.func_arg
    func_arg.argtypes = [c_int, c_void_p]
    func_arg.restype  = c_int

    py_func_getvalue = CFUNCTYPE(c_int, c_int)
    func_getvalue = py_func_getvalue(getvalue)

    print func_arg(c_int(10), func_getvalue)

if '__main__' == __name__:
    main()
